package com.vrms.app.controller;

import com.vrms.app.aop.SystemControllerLog;
import com.vrms.app.entity.Problem;
import com.vrms.app.service.ProblemService;
import com.vrms.app.tools.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("problem")

@CrossOrigin
public class ProblemController {
    @Resource
    private ProblemService problemService;

    @GetMapping("/listPage")
    @SystemControllerLog(description = "分页查询问题信息")
    public CommonResult listPage(int page, int size, String type){
        Map<String,Object> map = new HashMap();
        map.put("count",problemService.count(type));
        map.put("data",problemService.listPage(page,size,type));
        return CommonResult.success(map);
    }

    @PostMapping("/save")
    @SystemControllerLog(description = "添加问题")
    public CommonResult save(@RequestBody Problem problem){
        return CommonResult.success(problemService.save(problem));
    }

    @PostMapping("/update")
    @SystemControllerLog(description = "更新问题信息")
    public CommonResult update(@RequestBody Problem problem){
        return CommonResult.success(problemService.update(problem));
    }

    @PostMapping("/remove")
    @SystemControllerLog(description = "根据ID删除问题信息")
    public CommonResult remove(int id){
        return CommonResult.success(problemService.remove(id));
    }

    @PostMapping("/list")
    @SystemControllerLog(description = "查询所有问题信息")
    public CommonResult list(){
        return CommonResult.success(problemService.list());
    }
}
